<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
        :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="状态">
            <el-select v-model="form.status" placeholder="请选择" style="width: 370px;">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="详细地址" prop="addressLine1">
            <el-input v-model="form.addressLine1" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="form.addressLine2" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="省" prop="country">
            <el-input v-model="form.country" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="市" prop="city">
            <el-input v-model="form.city" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="区" prop="state">
            <el-input v-model="form.state" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="邮编" prop="zipCode">
            <el-input v-model="form.zipCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="收货人">
            <el-input v-model="form.operator" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;"
        @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="uid" label="客户号" />
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            {{scope.row.status=='1' ? "默认" : scope.row.status=='0' ? '正常' : '错误'}}
          </template>
        </el-table-column>
        <el-table-column prop="addressLine1" label="详细地址" />
        <el-table-column prop="addressLine2" label="手机号" />
        <el-table-column prop="country" label="省" />
        <el-table-column prop="city" label="市" />
        <el-table-column prop="state" label="区" />
        <el-table-column prop="zipCode" label="邮编" />
        <el-table-column prop="operator" label="收货人" />
        <el-table-column prop="createdAt" label="创建时间" />
        <el-table-column prop="updatedAt" label="修改时间" />
        <el-table-column v-if="checkPer(['admin','dccDizhi:edit','dccDizhi:del'])" label="操作" width="150px"
          align="center">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
  import crudDccDizhi from '@/api/dccDizhi'
  import CRUD, {
    presenter,
    header,
    form,
    crud
  } from '@crud/crud'
  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation'
  import udOperation from '@crud/UD.operation'
  import pagination from '@crud/Pagination'

  const defaultForm = {
    id: null,
    uid: null,
    type: null,
    status: null,
    addressLine1: null,
    addressLine2: null,
    country: null,
    city: null,
    state: null,
    zipCode: null,
    operator: null,
    createdAt: null,
    updatedAt: null
  }
  export default {
    name: 'DccDizhi',
    components: {
      pagination,
      crudOperation,
      rrOperation,
      udOperation
    },
    mixins: [presenter(), header(), form(defaultForm), crud()],
    cruds() {
      return CRUD({
        title: '毒查查地址',
        url: 'api/dccDizhi',
        idField: 'id',
        sort: 'id,desc',
        crudMethod: {
          ...crudDccDizhi
        }
      })
    },
    data() {
      return {
        options: [{
          value: 1,
          label: '默认'
        }, {
          value: 0,
          label: '正常'
        }],
        permission: {
          add: ['admin', 'dccDizhi:add'],
          edit: ['admin', 'dccDizhi:edit'],
          del: ['admin', 'dccDizhi:del']
        },
        rules: {
          addressLine1: [{
            required: true,
            message: '详细地址不能为空',
            trigger: 'blur'
          }],
          country: [{
            required: true,
            message: '省不能为空',
            trigger: 'blur'
          }],
          city: [{
            required: true,
            message: '市不能为空',
            trigger: 'blur'
          }],
          state: [{
            required: true,
            message: '区不能为空',
            trigger: 'blur'
          }],
          zipCode: [{
            required: true,
            message: '邮编不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      // 钩子：在获取表格数据之前执行，false 则代表不获取数据
      [CRUD.HOOK.beforeRefresh]() {
        return true
      }
    }
  }
</script>

<style scoped>

</style>